﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
  public  class ChiTietPhieuSuDungDichVuDAO
    {
      public List<ChiTietPhieuSuDungDichVuDTO> DanhSachChiTietPhieuSuDungDichVu()
      {
          List<ChiTietPhieuSuDungDichVuDTO> kq = new List<ChiTietPhieuSuDungDichVuDTO>();
          DataProvider dp = new DataProvider();
          string strsql = "select*from ChiTietPhieuSuDungDichVu";
          dp.Connect();
          SqlDataReader dr = dp.ExecuteQuery(strsql);
          if (dr.HasRows)
          {
              while (dr.Read())
              {
                  ChiTietPhieuSuDungDichVuDTO ct = new ChiTietPhieuSuDungDichVuDTO();
                  ct.DV_ID = int.Parse(dr["DV_ID"].ToString());
                  ct.PSDDV_ID = int.Parse(dr["PSDDV_ID"].ToString());
                  ct.SoLuong = int.Parse(dr["SoLuong"].ToString());
                  kq.Add(ct);
              }
          }
          dp.Disconnect();

          return kq;
      }
      public Boolean ThemChiTietPhieuSuDungDichVu(ChiTietPhieuSuDungDichVuDTO ct)
      {
          Boolean kq = false;
          DataProvider dp = new DataProvider();
          string strsql = "insert into ChiTietPhieuSuDungDichVu(DV_ID,PSDDV_ID,SoLuong)";
          strsql += "values(" + ct.DV_ID + "," + ct.PSDDV_ID + "," + ct.SoLuong + ")";
          dp.Connect();
          int i = dp.ExecuteNonQuery(strsql);
          dp.Disconnect();
          if (i != 0)
              kq = true;

          return kq;
      }
      public Boolean XoaChiTietPhieuSuDungDichVu(ChiTietPhieuSuDungDichVuDTO ct)
      {
          Boolean kq = false;
          DataProvider dp = new DataProvider();
          string strsql = "delete from ChiTietPhieuSuDungDichVu where DV_ID="+ct.DV_ID+" and PSDDV_ID="+ct.PSDDV_ID;
          dp.Connect();
          int i = dp.ExecuteNonQuery(strsql);
          dp.Disconnect();
          if (i != 0)
              kq = true;

          return kq;
      }
      public Boolean CapNhatChiTietPhieuSuDungDichVu(ChiTietPhieuSuDungDichVuDTO ct)
      {
          Boolean kq = false;
          DataProvider dp = new DataProvider();
          string strsql = "update ChiTietPhieuSuDungDichVu set SoLuong=" + ct.SoLuong + " where DV_ID=" + ct.DV_ID + " and PSDDV_ID=" + ct.PSDDV_ID; ;
          dp.Connect();
          int i = dp.ExecuteNonQuery(strsql);
          dp.Disconnect();
          if (i != 0)
              kq = true;

          return kq;
      }

    }
}
